import tables
let map = toOrderedTable {
  1000: ("M", "D", "C"),
  100: ("C", "L", "X"),
  10: ("X", "V", "I"),
  }

proc roman*(v: int): string =
  var n = v
  for key, (big, mid, small) in map:
    while n >= key:
      result.add big
      n.dec key
    if n >= key - key div 10:
      result.add small
      result.add big
      n.dec(key - key div 10)
    if n >= key div 2:
      result.add mid
      n.dec(key div 2)
    if n >= key div 2 - key div 10:
      result.add small
      result.add mid
      n.dec(key div 2 - key div 10)
    while n >= key div 10:
      result.add small
      n.dec(key div 10)